/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package EDT.obj;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.TreeMap;



/**
 *
 * @author ali
 */
public class Calendrier {
    
    private String titre;
    private ArrayList<Creneau> lesCreneaux ; 
    private Strategy strat;
    private int nbrperiode;
    private int periode;
    
    private HashMap<Integer,Date> guidePeriode;
    private HashMap<Integer,Integer> guideCouleur;
    private HashMap<Integer,Integer> guideNumCr;
    private HashMap<String,Integer> guideIdCompteur;
    private TreeMap<String,ArrayList<Integer>> guideIdecSelect;

    public TreeMap<String, ArrayList<Integer>> getGuideIdecSelect() {
        return guideIdecSelect;
    }
    
    public int getNbrperiode() {
        return nbrperiode;
    }

    public void setNbrperiode(int nbrperiode) {
        this.nbrperiode = nbrperiode;
    }

    public int getPeriode() {
        return periode;
    }

    public void setPeriode(int periode) {
        this.periode = periode;
    }
   

    public HashMap<Integer, Date> getGuidePeriode() {
        return guidePeriode;
    }

    public void setGuidePeriode(HashMap<Integer, Date> guidePeriode) {
        this.guidePeriode = guidePeriode;
    }
    public String getTitre() {
        return titre;
    }

    public void setTitre(String titre) {
        this.titre = titre;
    }
    
    public Calendrier(Strategy st){
        lesCreneaux = new ArrayList();
        guideCouleur = new HashMap();
        strat = st;
        guideNumCr = new HashMap();
        guideIdCompteur= new HashMap();
        guideIdecSelect = new TreeMap<>();
    }
    
    public Calendrier(Strategy st,int nbrperiode,int periode){
        lesCreneaux = new ArrayList();
        guideCouleur = new HashMap();
        strat = st;
        this.nbrperiode = nbrperiode;
        this.periode = periode;
        guideNumCr = new HashMap();
        guideIdCompteur= new HashMap();
        guideIdecSelect = new TreeMap<>();
    }

    public Creneau getFirstCreneau(){
        return lesCreneaux.get(0);
    }
        
    public void addCreneau(Creneau c){
        lesCreneaux.add(c);
        if (guideCouleur.get(strat.getId(c))== null){
            guideCouleur.put(strat.getId(c),guideCouleur.size()+1);
        }
        
        String idCompt = strat.getIdCompteur(c);
                
        Integer i=guideIdCompteur.get(idCompt);
        if(i==null){
             guideIdCompteur.put(idCompt,1);
             guideNumCr.put(c.getId(),1);
         }else{
             guideIdCompteur.put(idCompt,(i+1));
             guideNumCr.put(c.getId(),(i+1));
         }
       
    }

    public int getIdCouleur(int idc){
        
        int id = guideCouleur.get(idc);
        if( id > 14) return 14;
        return id;
    }
   
    
    
    public String perideToTableHTML(){
        String ret ="";
               
        ret += "<h3>"+getTitre()+"</h3><br/>";

        /*
         ret += "<select>";
              HashMap<Integer, Integer> hashMap = getGuidePeriode();
                for (Integer mapKey : hashMap.keySet())
                    ret += "<option>key= "+mapKey+"  value= "+hashMap.get(mapKey)+"</option>";
             ret += "</select>";   
        */
        
        
        
        
        if (lesCreneaux.size()!=0){
            
            
        int i=0;
        Creneau cr1 = lesCreneaux.get(i);
        
        DateFormat fullDateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL);
        
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
        DateFormat simpleFormat = new SimpleDateFormat("dd/MM");
        Date date1 = cr1.getDate();
        
        Calendar jour1 = Calendar.getInstance(); 
        jour1.setTime(date1);
        int nbrSem =1;
        
        
        while( !fullDateFormat.format(jour1.getTime()).substring(0,3).equals("lun") ) 
        jour1.add(Calendar.DATE, -1);
        
        Calendar datecc = Calendar.getInstance();
        datecc.setTime(new Date());
        
        int semestre =1;
        
       
        
        ret += strat.getBaliseDownloadIcs(cr1,getPeriode(),getNbrperiode());
        
        
        
      
        if(strat instanceof StratEc){
            if(getPeriode()!=0){
            
                semestre = getPeriode();
            }
            else{
                semestre =1;
                for (int kk=1;kk<=getNbrperiode();kk++)
                ret += "<li> <a href='#Semestre_"+kk+"' title='Semestre_"+kk+"'>Semestre "+kk+"</a></li>";
    
            }
        }
        
        if((cr1.getDate().before(new Date()) && lesCreneaux.get(lesCreneaux.size()-1).getDate().after(new Date()))|| cr1.getDate().equals(new Date()))
        ret+="<li> <a href='#today' title='Aujourd_hui'>Aujourd'hui</a></li><br/>";
        
        if(strat instanceof StratEc){
        //semestre = getGuidePeriode().get(lesCreneaux.get(i).getIdEc());
        ret+="<h3 id='Semestre_"+semestre+"'>Semestre "+semestre+"</h3>";
        }
        
        
        ret +="<div>\n" +"    \n" +"    <div id='calendrier3-nav'></div>\n" +"    \n" +"    \n" +
              "<table class='calendrier calendrier-etroit'>\n" +"<caption><span style='float: left;'>"+"Semaine "+nbrSem+" : "+dateFormat.format(jour1.getTime())+" </span></caption>"
                + "\n\n";
        
        //ret += "<tr><th colspan='41'><span style='float: left;'>+ "</span></th></tr>";  
        
        ret +="<tr>\n\n" +
            "<th></th>\n";
            int heure =8;
            for (int j=0; j<50 ; j++){
                ret += "<th>";   
                if((j % 4) == 0){
                ret += heure+"h";
                heure++;
                }
            ret +="</th>\n";
            }
            
        ret += "</tr>\n\n";
                  
        while (i < lesCreneaux.size() ){
        
            if (fullDateFormat.format(jour1.getTime()).substring(0,3).equals("sam")){
                  ret +="</table></div>";
                   jour1.add(Calendar.DATE, 2);
                   nbrSem++;
                   
                   ret+="<br/><br/><br/>";
                   
                                  
                   
                   if(strat instanceof StratEc)
                   //if(semestre == getGuidePeriode().get(lesCreneaux.get(i).getIdEc()) && lesCreneaux.get(i).getDate().before(jtest.getTime())){
                  
                       if(getGuidePeriode().get(semestre) != null && jour1.getTime().after(getGuidePeriode().get(semestre))){
                       semestre++;
                       ret+="<h3 id='Semestre_"+semestre+"'>Semestre "+semestre+"</h3>";
                      
                       
                        }
                       
                       
                   ret +="<div>\n" +"    \n" +"    <div id='calendrier3-nav'></div>\n" +"    \n" +"    \n" +
                        "<table class='calendrier calendrier-etroit'>\n\n\n";
        
                   ret += "<caption><span style='float: left;'>Semaine "+nbrSem+" : "+dateFormat.format(jour1.getTime())+ "</span></caption>"  ;  
        
                   ret +="<tr>\n\n" +
                   "<th></th>\n";
                   heure =8;
                     for (int j=0; j<50 ; j++){
                        ret += "<th>";   
                        if((j % 4) == 0){
                        ret += heure+"h";
                        heure++;
                        }
                        ret +="</th>\n";
                     }
            
                    ret += "</tr>\n\n";     
              }
            
        if(simpleFormat.format(jour1.getTime()).equals(simpleFormat.format(datecc.getTime())))
        ret += "<tr id='today'>\n<th>"+"*"+fullDateFormat.format(jour1.getTime()).substring(0,3)+"*"+"<br/>"+simpleFormat.format(jour1.getTime()) +"</th>\n";
        else
        ret += "<tr>\n<th>"+fullDateFormat.format(jour1.getTime()).substring(0,3)+"<br/>"+simpleFormat.format(jour1.getTime()) +"</th>\n";
            
        int caseInt =1;
        
        while( i<lesCreneaux.size()  && lesCreneaux.get(i).getDate().equals(jour1.getTime())){
         
               Creneau c = lesCreneaux.get(i);

               int heureD = c.getHdebut() / 100;
               int heureF = c.getHfin() / 100;
               int minD = c.getHdebut() % 100;
               int minF = c.getHfin() % 100;
               
               
               int caseDepart = ((heureD - 8) * 4) + (minD / 15);
               int caseFin = ((heureF - 8) * 4) + (minF / 15);
               
               
               for (int j=caseInt; j<=caseDepart; j++){
                   ret +="<td></td>";
               
               }
               
               ret += "<td colspan='"+(caseFin-caseDepart)+"' > <div class='calendrier-arial10 calendrier-evenement calendrier-couleur";
               ret += getIdCouleur(strat.getId(c));
               
               if(!c.getType().toUpperCase().equals("CM")) ret+="i";
               
               ret += "'> ";
               String hdebut = String.valueOf(c.getHdebut()).replace(String.valueOf(c.getHdebut()).substring(0, String.valueOf(c.getHdebut()).length()-2), String.valueOf(c.getHdebut()).substring(0, String.valueOf(c.getHdebut()).length()-2)+":");
               String hfin =   String.valueOf(c.getHfin()).replace(String.valueOf(c.getHfin()).substring(0, String.valueOf(c.getHfin()).length()-2), String.valueOf(c.getHfin()).substring(0, String.valueOf(c.getHfin()).length()-2)+":");
            ret +="<div style='font-weight: bold;'>"+hdebut+" - "+hfin+"</div>";
            
            if(c.getType().toUpperCase().equals("CM"))
            ret += c.getType().toUpperCase()+guideNumCr.get(c.getId())+"/"+guideIdCompteur.get(strat.getIdCompteur(c))+" : "+c.getFormation()+" : "+c.getEc()+"<br/>"+"Ens: "+c.getEnseignant()+"<br/>"+"salle: "+c.getSalle()+"</div>"+"</td>";
            else
            ret += c.getType().toUpperCase()+guideNumCr.get(c.getId())+"/"+guideIdCompteur.get(strat.getIdCompteur(c))+" G"+c.getnGp()+" : "+c.getFormation()+" : "+c.getEc()+"<br/>"+"Ens: "+c.getEnseignant()+"<br/>"+"salle: "+c.getSalle()+"</div>"+"</td>";    
            
            
            caseInt = caseFin+1;
               if (i==lesCreneaux.size()-1 || !lesCreneaux.get(i+1).getDate().equals(jour1.getTime())){
                    
               for (int k=caseInt; k<51; k++){
                   ret +="<td></td>";
                  }
                  caseInt = 51;
               }
               
               i++;
               
           } 
           
               for (int k=caseInt; k<51; k++){
                   ret +="<td></td>";
               }
              
               caseInt=51;
               
               ret += "</tr>";
               jour1.add(Calendar.DATE, 1);
               
               
               
               
            } 
            
        ret +="</table></div>";
        }else
            ret +="Il n'y a pas de créneau programmé ! ";
        
        return ret;
    }
    

    
   public String perideToTableHTMLClick(String type){
        
    String ret ="";
               
                
        if (lesCreneaux.size()!=0){
        int i=0;
        Creneau cr1 = lesCreneaux.get(i);
        
        DateFormat fullDateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL);
        
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
        DateFormat simpleFormat = new SimpleDateFormat("dd/MM");
        Date date1 = cr1.getDate();
        
        Calendar jour1 = Calendar.getInstance(); 
        jour1.setTime(date1);
        int nbrSem =1;
        
        
        while( !fullDateFormat.format(jour1.getTime()).substring(0,3).equals("lun") ) 
        jour1.add(Calendar.DATE, -1);
       
        
        Calendar datecc = Calendar.getInstance();
        datecc.setTime(new Date());
        
        int semestre =1;
        
        if(strat instanceof StratEc){
            if(getPeriode()!=0){
            
                semestre = getPeriode();
            }
            else{
                semestre =1;
                for (int kk=1;kk<=getNbrperiode();kk++)
                ret += "<li> <a href='#Semestre_"+kk+"' title='Semestre_"+kk+"'>Semestre "+kk+"</a></li>";
    
            }
        }
        
        if((cr1.getDate().before(new Date()) && lesCreneaux.get(lesCreneaux.size()-1).getDate().after(new Date())) || cr1.getDate().equals(new Date()))
        ret+="<li> <a href='#today' title='Aujourd_hui'>Aujourd'hui</a></li><br/>";
        
        if(strat instanceof StratEc){
        //semestre = getGuidePeriode().get(lesCreneaux.get(i).getIdEc());
        ret+="<h3 id='Semestre_"+semestre+"'>Semestre "+semestre+"</h3>";
        }
        
        
        ret +="<div>\n" +"    \n" +"    <div id='calendrier3-nav'></div>\n" +"    \n" +"    \n" +
              "<table class='calendrier calendrier-etroit'>\n" +"<caption><span style='float: left;'>"+"Semaine "+nbrSem+" : "+dateFormat.format(jour1.getTime())+" </span></caption>"
                + "\n\n";
                
        ret +="<tr>\n\n" +
            "<th></th>\n";
            int heure =8;
            for (int j=0; j<50 ; j++){
                ret += "<th>";   
                if((j % 4) == 0){
                ret += heure+"h";
                heure++;
                }
            ret +="</th>\n";
            }
            
        ret += "</tr>\n\n";
                  
        while (i < lesCreneaux.size() ){
        
            if (fullDateFormat.format(jour1.getTime()).substring(0,3).equals("sam")){
                  ret +="</table></div>";
                   jour1.add(Calendar.DATE, 2);
                   nbrSem++;
                   
                   ret+="<br/><br/><br/>";
                   
                  
                   
                   if(strat instanceof StratEc)
                   if(getGuidePeriode().get(semestre) != null && jour1.getTime().after(getGuidePeriode().get(semestre))){
                       semestre++;
                       ret+="<h3 id='Semestre_"+semestre+"'>Semestre "+semestre+"</h3>";
                        }
                       
                   ret +="<div>\n" +"    \n" +"    <div id='calendrier3-nav'></div>\n" +"    \n" +"    \n" +
                        "<table class='calendrier calendrier-etroit'>\n\n\n";
        
                    ret += "<caption><span style='float: left;'>Semaine "+nbrSem+" : "+dateFormat.format(jour1.getTime())+ "</span></caption>"  ;  
        
                    ret +="<tr>\n\n" + 
                    "<th></th>\n";
                    heure =8;
                     for (int j=0; j<50 ; j++){
                        ret += "<th>";   
                        if((j % 4) == 0){
                        ret += heure+"h";
                        heure++;
                        }
                        ret +="</th>\n";
                     }
            
                    ret += "</tr>\n\n";     
              }
            
        if(simpleFormat.format(jour1.getTime()).equals(simpleFormat.format(datecc.getTime())))
        ret += "<tr id='today'>\n<th>"+"*"+fullDateFormat.format(jour1.getTime()).substring(0,3)+"*"+"<br/>"+simpleFormat.format(jour1.getTime()) +"</th>\n";
        else
        ret += "<tr>\n<th>"+fullDateFormat.format(jour1.getTime()).substring(0,3)+"<br/>"+simpleFormat.format(jour1.getTime()) +"</th>\n";
            
        int caseInt =1;
        
        while( i<lesCreneaux.size()  && lesCreneaux.get(i).getDate().equals(jour1.getTime())){
         
               Creneau c = lesCreneaux.get(i);
            
               int heureD = c.getHdebut() / 100;
               int heureF = c.getHfin() / 100;
               int minD = c.getHdebut() % 100;
               int minF = c.getHfin() % 100;
               
               int caseDepart = ((heureD - 8) * 4) + (minD / 15);
               int caseFin = ((heureF - 8) * 4) + (minF / 15);
                              
               for (int j=caseInt; j<=caseDepart; j++){
                   ret +="<td></td>";
               
               }
               
               ret += "<td colspan='"+(caseFin-caseDepart)+"' > <div id='"+c.getId()+"' class='calendrier-arial10 calendrier-evenement calendrier-couleur";
               if (c.getVisible().equals("true"))
               ret += getIdCouleur(strat.getId(c));
               else
               ret += "0";
               
               
               if(!c.getType().toUpperCase().equals("CM")){ 
               ret+="i";
               ret += "'> <input  type='checkbox' onclick='compt("+c.getId()+")' name='options' value='"+c.getId()+"'/><a  href='javascript:;' onclick='Supprimer("+c.getId()+")' class='cr-couleur"+getIdCouleur(strat.getId(c))+"i' >";
               }else ret += "'> <input type='checkbox' onclick='compt("+c.getId()+")' name='options' value='"+c.getId()+"'/><a  href='javascript:;' onclick='Supprimer("+c.getId()+")' class='cr-couleur"+getIdCouleur(strat.getId(c))+"'>";
               
               String hdebut = String.valueOf(c.getHdebut()).replace(String.valueOf(c.getHdebut()).substring(0, String.valueOf(c.getHdebut()).length()-2), String.valueOf(c.getHdebut()).substring(0, String.valueOf(c.getHdebut()).length()-2)+":");
               String hfin =   String.valueOf(c.getHfin()).replace(String.valueOf(c.getHfin()).substring(0, String.valueOf(c.getHfin()).length()-2), String.valueOf(c.getHfin()).substring(0, String.valueOf(c.getHfin()).length()-2)+":");
            ret += "<div style='font-weight: bold;display:inline ;'>"+hdebut+" - "+hfin+"</div><br/>";
            
            if(guideIdecSelect.get(c.getEc()+" "+c.getType().toUpperCase()) == null){
                    guideIdecSelect.put(c.getEc()+" "+c.getType().toUpperCase(), new ArrayList<Integer>());
                    guideIdecSelect.get(c.getEc()+" "+c.getType().toUpperCase()).add(c.getId());       
            }else{
                guideIdecSelect.get(c.getEc()+" "+c.getType().toUpperCase()).add(c.getId());
            }
            
            if(c.getType().toUpperCase().equals("CM"))
            ret += c.getType().toUpperCase()+guideNumCr.get(c.getId())+"/"+guideIdCompteur.get(strat.getIdCompteur(c))+" : "+c.getFormation()+" : "+c.getEc()+"<br/>"+"Ens: "+c.getEnseignant()+"<br/>"+"salle: "+c.getSalle()+"</a></div>"+"</td>";
            else
            ret += c.getType().toUpperCase()+guideNumCr.get(c.getId())+"/"+guideIdCompteur.get(strat.getIdCompteur(c))+" G"+c.getnGp()+" : "+c.getFormation()+" : "+c.getEc()+"<br/>"+"Ens: "+c.getEnseignant()+"<br/>"+"salle: "+c.getSalle()+"</a></div>"+"</td>";    
            
            
            caseInt = caseFin+1;
               if (i==lesCreneaux.size()-1 || !lesCreneaux.get(i+1).getDate().equals(jour1.getTime())){
                    
               for (int k=caseInt; k<51; k++){
                   ret +="<td></td>";
                  }
                  caseInt = 51;
               }
               
               i++;
               
           } 
           
               for (int k=caseInt; k<51; k++){
                   ret +="<td></td>";
               }
              
               caseInt=51;
               
               ret += "</tr>";
               jour1.add(Calendar.DATE, 1);

            } 
            
        ret +="</table></div>";
        
        String tabSelect= "<br/>";
          tabSelect += "<fieldset>";
        
        
        tabSelect +="<legend>    Table de sélection automatique :   </legend>";
        tabSelect += "<table>";
              TreeMap<String, ArrayList<Integer>> hashMap = getGuideIdecSelect();
              
              int j=0;
                for (String mapKey : hashMap.keySet()){
                    if(j % 3 == 0)tabSelect +="<tr>";
                    j++;
                    tabSelect += "<td style='padding-left: 10px;'><li> <a href='#"+hashMap.get(mapKey).get(0)+"' title='"+mapKey+"'>"+mapKey+" ("+hashMap.get(mapKey).size()+") </a></li></td><td style='padding-right: 40px;'><input type='checkbox' onClick=\"selection(new Array(";
                    for (Integer idcr : hashMap.get(mapKey)){
                        tabSelect += "'"+idcr+"',";
                        }
                    tabSelect = tabSelect.substring(0, tabSelect.length()-1);
                    tabSelect += "),this)\" /></td>";
                    if(j % 3 == 0)tabSelect +="</tr>";
                 //tabSelect +="</tr>";           
                }
                if(!tabSelect.subSequence(tabSelect.length()-5, tabSelect.length()).equals("</tr>"))
                    tabSelect +="</tr>";
             
                if(type.equals("supression")){
                    tabSelect ="<form id='suppr' method='POST' action='SupprCrAct.do' target='section'>\n"+tabSelect;
                    tabSelect += "</table></fieldset><br/><input type='button' value='Supprimer' onclick='suppresion()'/><br/><br/>";   
                }else{
                //if(type.equals("modification")){
                tabSelect += "</table></fieldset>"
                        + "<br/>";
                tabSelect ="<form id='modif' method='POST' action='ModifCrAct.do' target='section'>\n"+tabSelect;
                    
                String optionModif = "<fieldset>";
        
                ArrayList<Salle> salle = EDT.api.API.getSalle();
                ArrayList<Intervenant> interv = EDT.api.API.getAllIntervenant();
                optionModif +="<legend>Sélectionnez le type de modification à faire :  </legend>";
                optionModif += "<table>";
                
                
                optionModif += "<tr><td><input type='radio' name='typeModif' value='interv' onclick='active(this)'/>Intervenant</td>";
                optionModif += "<td><select id='interv' name='interv' style='visibility:hidden;'>";
                for (Intervenant ii : interv)
                optionModif +="<option value="+ii.getId()+">"+ii.getPrenom()+" "+ii.getNom()+"</option>";
                optionModif +="</select></td></tr>";
                
                
                optionModif += "<tr><td><input type='radio' name='typeModif' value='salle' onclick='active(this)'/>Salle</td>"
                        + "<td><select id='salle' name='salle' style='visibility:hidden;'>";
                for (Salle s : salle)
                optionModif +="<option value="+s.getId()+">"+s.getNom()+"</option>";
                optionModif +="</select></td></tr>";
                
                
                optionModif += "<tr><td><input type='radio' name='typeModif' value='hdebut' onclick='active(this)'/>Heure début</td>";
                optionModif +="<td><input type='text' name='hdebut' id='hdebut' value='' onclick='' style='visibility:hidden;' /></td></tr>";
                 
                optionModif += "<tr><td><input type='radio' name='typeModif' value='hfin' onclick='active(this)'/>Heure Fin</td>";
                optionModif +="<td><input type='text' name='hfin' id='hfin' value='' onclick='' style='visibility:hidden;' /></td></tr>";
                 

                
                optionModif += "<tr><td>"
                        + "<input type='radio' name='typeModif' value='jour' onclick='active(this)'/>Jour</td>"
                        + "<td><input type='text' name='jour' id='jour' value='' onclick='' style='visibility:hidden;' /> </td></tr>";
                
                optionModif += "<tr><td><input type='radio' name='typeModif' value='duree' onclick='active(this)'/>Durée </td>"
                        + "<td><select name='duree' id='duree' style='visibility:hidden;'>";
                optionModif += "    <option value='30'>30m</option>";
                optionModif += "    <option value='45'>45m</option>";
                optionModif += "    <option value='60'>1h</option>";
                optionModif += "    <option value='75'>1h15</option>";
                optionModif += "    <option value='90'>1h30</option>";
                optionModif += "    <option value='105'>1h45</option>";
                optionModif += "    <option value='120'>2h</option>";
                optionModif += "</select>";
        
                optionModif += "</td></tr>";
                
                optionModif += "<tr><td><input type='radio' name='typeModif' value='timeDecal' onclick='active(this)'/>Décaler le(s) créneau(x) de</td>";
                optionModif += "<td><div id='timeDecal' style='visibility:hidden;'><input type='text' name='timeDecal' id='timeDecalage' value='' onclick=''/><input type='radio' name='decalage' value='+' checked> + <input type='radio' name='decalage' value='-'> - </div></td>";
                optionModif += "</tr>";
                
                
                optionModif += "<tr><td><input type='radio' name='typeModif' value='visib' onclick='active(this)'/>Visibilité</td>";
                optionModif   += "<td><select id='visib' name='visib' style='visibility:hidden;'>";
                optionModif   += "<option value='true'>Public</option>";
                optionModif   += "<option value='fals'>Privé</option>";
                optionModif   += "</select></td>";
                optionModif += "</tr>";
                
                                        
                optionModif += "</table></fieldset><br/>"
                        + "<input type='button' value='Modifier' onclick='modifier()'/>"
                  + "<br/><br/>"; 
                
                 
                tabSelect += optionModif  ;
                }
                     
        ret = "<h3>"+getTitre()+"</h3>"+tabSelect+ret;
        
        }else
            ret +="Il n'y a pas de créneau programmé ! ";
        
        return ret;
    }
    
    
    public ArrayList<String>  getIcsForm(){
       
        ArrayList<String> ret = new ArrayList<>();
       DateFormat timeStamp = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
       Date toDay = new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'");
       String hdebut;
       String hfin;
        
        ret.add("BEGIN:VCALENDAR");
        ret.add("VERSION:2.0");
        ret.add("CALSCALE:GREGORIAN"); 
        
        for (Creneau c : lesCreneaux){
       
        hdebut = String.valueOf(c.getHdebut());
        hfin = String.valueOf(c.getHfin());
    
        if(hdebut.length()==3){hdebut="0"+hdebut;}
        if(hfin.length()==3){hfin="0"+hfin;}
        ret.add("BEGIN:VEVENT");    
        ret.add("DTSTART;TZID=Europe/Paris:"+dateFormat.format(c.getDate())+hdebut+"00");
        ret.add("DTEND;TZID=Europe/Paris:"+dateFormat.format(c.getDate())+hfin+"00");
        ret.add("DTSTAMP;TZID=Europe/Paris:"+timeStamp.format(toDay));
     
        if(c.getType().toUpperCase().equals("CM")){
            ret.add("SUMMARY:"+c.getType().toUpperCase()+guideNumCr.get(c.getId())
                +"/"+guideIdCompteur.get(strat.getIdCompteur(c))+" "+c.getEc()+" "
                    +c.getFormation());
        }else{
            ret.add("SUMMARY:"+c.getType().toUpperCase()+guideNumCr.get(c.getId())
                +"/"+guideIdCompteur.get(strat.getIdCompteur(c))+" "+c.getEc()+" G"+c.getnGp()
                +" "+c.getFormation());
        }
       
        ret.add("DESCRIPTION:"+c.getType().toUpperCase()+guideNumCr.get(c.getId())
                +"/"+guideIdCompteur.get(strat.getIdCompteur(c))+" Grp:"+c.getnGp()
                +" Formation:"+c.getFormation()+" Ec:"+c.getEc()+" Intervenant:"+c.getEnseignant());
        ret.add("ATTENDEE:mailto:"+c.getEmail());
        ret.add("LOCATION:Salle "+c.getSalle());
        ret.add("END:VEVENT");
        
        }
        
   
        ret.add("END:VCALENDAR");
        
        
        
       return ret;
        
    }
                
}
